<?php
namespace wogu2\mvc;

use wogu2\stdlib\RequestInterface;
use wogu2\mvc\router\RouterStackInterface;
use wogu2\stdlib\ResponseInterface;
use wogu2\mvc\DispatcherInterface;

class Application implements ApplicationInterface
{
    private $_request = null;
    private $_router = null;
    private $_response = null;
    private $_dispatcher = null;
    private $_returnResponse = false;
    
    public function setRequest(RequestInterface $request) {
        $this->_request = $request;
    }
    
    public function setRouter(RouterStackInterface $router) {
        $this->_router = $router;
    }
    
    public function setResponse(ResponseInterface $response) {
        $this->_response = $response;
    }
    
    public function setDispatcher(DispatcherInterface $dispatcher) {
        $this->_dispatcher = $dispatcher;
    }
    
    public function setReturnResponse($returnResponse) {
        $this->_returnResponse = $returnResponse;
    }
    
    public function bootstrap() {
        if(!$this->_router->match($this->_request)) {
            throw new \InvalidArgumentException(
                'route failed'
            );
        }
        print_r($this->_router);exit;

        $this->_dispatcher->setRuntime($runtime);
        $this->_dispatcher->dispatch();
        
        $this->_response->setRuntime($runtime);
        if($this->_returnResponse) {
            return $this->_response;
        }
        
        $this->_response->send();
    }
}